const webpack = require('webpack')
const path = require('path');

module.exports = {
    // 基本路径
    publicPath: './',
    pages: {
        index: {
            // entry for the page
            entry: 'src/main.js',
            // the source template
            template: 'public/index.html',
            // output as dist/index.html
            filename: 'index.html',
            // when using title option,
            // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
            title: '测试-web',
            // chunks to include on this page, by default includes
            // extracted common chunks and vendor chunks..

            chunks: ['chunk-vendors', 'chunk-common', 'index']
        }
        // when using the entry-only string format,
        // template is inferred to be `public/subpage.html`
        // and falls back to `public/index.html` if not found.
        // Output filename is inferred to be `subpage.html`.
        // subpage: 'src/subpage/main.js'
    },
    // css: {
    //     loaderOptions: {
    //         less: {
    //             additionalData: `@import "./src/assets/css/theme.less";`
    //         }
    //     }
    // },
    // 全局变量配置
    chainWebpack: (config) =>{
        config.resolve.alias
        .set('@', path.join(__dirname, 'src'))
        .set('static', path.join(__dirname, 'public/static'))
        // 引入全局less变量
        const oneOfsMap = config.module.rule('less').oneOfs.store
        oneOfsMap.forEach(item => {
            item
                .use('sass-resources-loader')
                .loader('sass-resources-loader')
                .options({
                    // 这里填入你的样式文件地址,也可以是数组
                    resources: './src/assets/css/theme.less'
                })
                .end()
        })
    },
    // 修改webpack配置
    configureWebpack: (config) => {
        // 配置全局引入
        const providePlugin = new webpack.ProvidePlugin({
            $http: path.join(__dirname, 'src/api/http.js')
        })
        config.plugins.push(providePlugin)
    },
    devServer: {
        port: 3008,
        hot: true,
        overlay: {
            // 显示在页面上
            warnings: false,
            errors: true
        },
        proxy: {
        	'/lifeSite': {
                target: 'http://127.0.0.1:3002/lifeSite/',
                changeOrigin: true,
                pathRewrite: {
                    '^/lifeSite': '/'
                }
            }
        }
    }
}
